//
//  Health.m
//  LearningCocos
//
//  Created by abyssos on 2014. 3. 4..
//  Copyright (c) 2014년 ainhan. All rights reserved.
//

#import "Health.h"

@implementation Health

@synthesize healthAnim;

- (void)dealloc {
    [healthAnim release];
    [super dealloc];
}

- (void)changeState:(CharacterStates)newState {
    if(newState == kStateSpawning) {
        healthAnim.restoreOriginalFrame = NO;
        id action = [CCRepeatForever actionWithAction:[CCAnimate actionWithAnimation:healthAnim]];
        [self runAction:action];
    } else {
        [self setVisible:NO]; // Picked up
        [self removeFromParentAndCleanup:YES];
    }
}

- (void)updateStateWithDeltaTime:(ccTime)deltaTime andListOfGameObjects:(CCArray *)listOfGameObjects {
    float groundHeight = screenSize.height * 0.065f;
    
    if([self position].y > groundHeight)
        [self setPosition:ccp([self position].x, [self position].y - 5.0f)];
}

- (void)initAnimations {
    [self setHealthAnim:[self loadPlistForAnimationWithName:@"healthAnim" andClassName:NSStringFromClass([self class])]];
}

- (id)init {
    if((self = [super init])) {
        screenSize = [CCDirector sharedDirector].winSize;
        [self initAnimations];
        [self changeState:kStateSpawning];
        gameObjectType = kPowerUpTypeHealth;
    }
    
    return self;
}


@end
